﻿using System.Collections.Generic;
using System.Reflection;

using System.Linq;

namespace SLTimeZoneHelper
{
	public class CommonZones
	{
		private static IEnumerable<TimeZone> _zones;

		public static IEnumerable<TimeZone> GetZones()
		{
			if (_zones == null)
			{
				using (var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SLTimeZoneHelper.CommonZones.xml"))
				{
					_zones = Util.Serializer.Deserialize(resourceStream);
				}
			}

			return _zones;
		}

		public static IEnumerable<string> GetZoneNames()
		{
			return GetZones().Select(x => x.UserInterfaceName);
		}

		public static TimeZone GetZoneByCode(int code)
		{
			return GetZones().FirstOrDefault(x => x.TimeZoneCode == code);
		}
	}
}